package com.ald.plane_tool.adapter;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.ald.plane_tool.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class HomeAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {
    public HomeAdapter( @Nullable List<Integer> data) {
        super(R.layout.home_itm, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, Integer integer) {
        int adapterPosition = baseViewHolder.getAdapterPosition();
        baseViewHolder.setBackgroundResource(R.id.iv_map,integer);
        baseViewHolder.itemView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (adapterPosition){
                    case 0:
                        setBeacgerd(baseViewHolder,event,R.mipmap.hmapa,R.mipmap.homemapq);
                        break;
                    case 1:
                        setBeacgerd(baseViewHolder,event,R.mipmap.hmapb,R.mipmap.homemapw);
                        break;
                    case 2:
                        setBeacgerd(baseViewHolder,event,R.mipmap.hmapc,R.mipmap.homemape);
                        break;
                    case 3:
                        setBeacgerd(baseViewHolder,event,R.mipmap.hmapd,R.mipmap.homemapr);
                        break;
                    case 4:
                        setBeacgerd(baseViewHolder,event,R.mipmap.hmapf,R.mipmap.homemapt);
                        break;
                    case 5:
                        setBeacgerd(baseViewHolder,event,R.mipmap.hmape,R.mipmap.homemapy);

                        break;

                }
                return false;
            }
        });


    }
    private void setBeacgerd(BaseViewHolder baseViewHolder,MotionEvent event,Integer UP,Integer DOWN){
        if(event.getAction() == MotionEvent.ACTION_UP){
            Log.d("test", "cansal button ---> cancel");
            baseViewHolder.setBackgroundResource(R.id.iv_map,UP);
        }
        if(event.getAction() == MotionEvent.ACTION_DOWN){
            Log.d("test", "cansal button ---> down");
            baseViewHolder.setBackgroundResource(R.id.iv_map,DOWN);
        }
    }
    @Override
    public int getItemViewType(int position) {
        return position;
    }
}
